{# 必须传入course_org #}
{% extends 'base.html' %}

{% load staticfiles %}

{% block title %}授课机构{% endblock %}

{% block head_middle_nav %}
    <div class="middle companyheader">
        <div class="wp">
            <img class="fl" style="width: 112px;height: 103px" src="{{  MEDIA_URL }}{{ course_org.image }}"/>
            <div class="head fl">
                <h1>
                    {{ course_org.name }}
                    <img src="{% static 'images/authentication.png' %}"/>
                    <img src="{% static 'images/gold.png' %}"/>
                </h1>
                <p class="fl">
                    <span class="fl" style="margin-top:8px;color:#848484;">推荐指数： </span>
                    <span class="precision company-credit" data-star-scope="5.0"></span>
                    <span class="key">5.0</span>
                </p>
            </div>
            <div class="btn fr collectionbtn  notlogin
                 " data-favid="22" data-fav-type="1">
                {% if has_fav %}已{% endif %}收藏
            </div>
        </div>
    </div>
{% endblock %}

{% block custom_bread %}
    <section>
        <div class="wp">
            <ul class="crumbs">
                <li><a href="{% url 'index' %}">首页</a>></li>
                <li><a href="{% url 'org:org_list' %}">课程机构</a>></li>
                {% if current_page == 'homepage' %}
                    <li>机构首页</li>
                {% elif current_page == 'courses' %}
                    <li>机构课程</li>
                {% elif current_page == 'desc' %}
                    <li>机构介绍</li>
                {% elif current_page == 'teachers' %}
                    <li>机构讲师</li>
                {% endif %}
            </ul>
        </div>
    </section>
{% endblock %}

{% block content %}
    <section>
        <div class="wp list personal_list comp">
            {% block org_detail_left %}
                <div class="left">
                    <ul>
                        <li class="{% if current_page == 'homepage' %}active2{% endif %}">
                            <a href="{% url 'org:org_home' course_org.id %}">机构首页</a>
                        </li>
                        <li class="{% if current_page == 'courses' %}active2{% endif %}">
                            <a href="{% url 'org:org_course' course_org.id %}">机构课程</a>
                        </li>
                        <li class="{% if current_page == 'desc' %}active2{% endif %}">
                            <a href="{% url 'org:org_desc' course_org.id %}">机构介绍</a>
                        </li>
                        <li class="{% if current_page == 'teachers' %}active2{% endif %}">
                            <a href="{% url 'org:org_teacher' course_org.id %}">机构讲师</a>
                        </li>
                    </ul>
                </div>
            {% endblock %}

            {% block org_detail_right %}
            {% endblock %}
        </div>
    </section>
{% endblock %}

{% block custom_js %}
    <script type="text/javascript">
        //收藏分享
        //收藏分享
        function add_fav(current_elem, fav_id, fav_type) {
            $.ajax({
                cache: false,
                type: "POST",
                url: "{% url 'org:add_fav' %}",
                data: {'fav_id': fav_id, 'fav_type': fav_type},
                async: true,
                beforeSend: function (xhr, settings) {
                    xhr.setRequestHeader("X-CSRFToken", "{{ csrf_token }}");
                },
                success: function (data) {
                    if (data.status == 'fail') {
                        if (data.msg == '用户未登录') {
                            window.location.href = "/login/";
                        } else {
                            current_elem.text(data.msg)
                        }

                    } else if (data.status == 'success') {
                        current_elem.text(data.msg)
                    }
                }
            });
        }

        $('.collectionbtn').on('click', function () {
            add_fav($(this), {{ course_org.id }}, 2);
        });

        $(function () {
            var $precision = $('.precision'),
                score = $precision.attr('data-star-scope'),
                option = {
                    half: true,
                    path: '{% static 'images/' %}',
                    precision: true,
                    size: 24,
                    starOff: 'g_star.png',
                    starOn: 'r_star.png',
                    starHalf: 'h_star.png',
                    hints: ['极差', '差', '一般', '好评', '非常满意'],
                    noRatedMsg: '暂时还未获得评价！',
                    readOnly: true,
                    score: score
                };
            $precision.raty(option);

            $('.jsFavBtn').on('click', function () {
                var type = $(this).attr('data-fav-type');
                if (type == '1') {
                    favPraise($(this), 'fav', 1, '收藏');

                } else if (type == '3') {
                    favPraise($(this), 'fav', 3);

                } else if (type == '11') {
                    favPraise($(this), 'pra', 1);

                } else if (type == '4') {
                    favPraise($(this), 'fav', 4);

                }
            });
        })
    </script>


    <script type="text/javascript">
        $(function () {
            $('.recordbtn1').click(function () {
                $('.recordbox1').show();
            });
            $('.recordbtn2').click(function () {
                $('.recordbox2').show();
            });

            $('.imgslide').unslider({
                speed: 500,               //  The speed to animate each slide (in milliseconds)
                delay: 3000,              //  The delay between slide animations (in milliseconds)
                complete: function () {
                },  //  A function that gets called after every slide animation
                keys: true,               //  Enable keyboard (left, right) arrow shortcuts
                dots: true,               //  Display dot navigation
                fluid: false              //  Support responsive design. May break non-responsive designs
            });
            var unslider = $('.imgslide').unslider();
            $('.unslider-arrow').click(function () {
                var fn = this.className.split(' ')[1];
                unslider.data('unslider')[fn]();
            });
        });
    </script>
{% endblock %}